/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.lom.examples;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ontspace.MetadataRepository;
import org.ontspace.owl.util.MetadataRepositoryConfigException;
import org.ontspace.lom.LOMQueryManager;
import org.ontspace.owl.MetadataRepositoryFactory;
import org.ontspace.owl.MetadataRepositoryImpl;
import org.ontspace.owl.util.OntologyNotInRepositoryException;

/**
 * Example for a Learning object metadata  Query
 */
public class ExampleGetLOMetadata {

    public static void main(String args[]) throws MetadataRepositoryConfigException,
            OntologyNotInRepositoryException {


        HashMap params =
                new HashMap();
        params.put(MetadataRepository.STORAGE_URI_PARAM,
                "jdbc:mysql://127.0.0.1/ejemplo");
        params.put(MetadataRepository.USER_NAME_PARAM,
                "root");
        params.put(MetadataRepository.PWD_PARAM,
                "password");
        params.put(MetadataRepositoryImpl.DB_DRIVER_PARAM,
                "com.mysql.jdbc.Driver");
        params.put(MetadataRepositoryImpl.DB_TYPE_PARAM,
                "MySQL");
        params.put(MetadataRepositoryImpl.DC_SCHEMA_PATH_PARAM,
                "C:/mydirectory/cvs/ont-space/etc/output.owl");
        try {

            params.put(MetadataRepository.PUBLIC_REP_URI_PARAM,
                    new URI("http://o-space.org/rep"));

        } catch (URISyntaxException ex) {
            Logger.getLogger(ExampleGetLOMetadata.class.getName()).log(Level.SEVERE,
                    null, ex);
        }

        MetadataRepository rep =
                MetadataRepositoryFactory.openMetadataRepository(params);

        // Get session

        HashMap paramsLOM =
                new HashMap();
        paramsLOM.put("uri1", "http://www.cc.uah.es/ie/ont/lom-ospace");

        //Get the queryManager
        LOMQueryManager qm =
                (LOMQueryManager) rep.getQueryManager
                    ("org.ontspace.lom.owl.LOMQueryManagerImpl",paramsLOM);



        String loId =
                paramsLOM.get("uri1").toString() + "#learningObject0";

//      UNCOMENT THIS FOR ANOTHER METADATA QUERY        
        Set<String> titleResults =
                qm.getLOMTitle(loId, "");

        for (Iterator itTitle =
                titleResults.iterator(); itTitle.hasNext();) {
            System.out.println("Title = " + itTitle.next().toString());
        }
//
//
//        Set<String> descriptionResults = qm.getLOMDescription(loId, "");
//
//        for (Iterator itDescription = descriptionResults.iterator();
//                itDescription.hasNext();) {
//            System.out.println("Description = " +
//                    itDescription.next().toString());
//        }
//
//        Set<String> keywordResults =
//                qm.getLOMKeywords(loId, "");
//
//        for (Iterator itKeyword = keywordResults.iterator();
//                itKeyword.hasNext();) {
//            System.out.println("Keyword = " +
//                    itKeyword.next().toString());
//        }
//
//        String duration = "";
//
//        duration = qm.getLOMDuration(loId);
//        System.out.println("Duration: " + duration);
//
//        Set<String> durationDescription = qm.getLOMDurationDescription(loId, "");
//        for (Iterator itDurDesc = durationDescription.iterator();
//                itDurDesc.hasNext();) {
//            System.out.println("Duration Description: " + itDurDesc.next().
//                    toString());
//        }
//
//        Set<String> rightDescriptionResults = qm.getLOMRightsDescription(loId,
//                "");
//
//        for (Iterator itDescription = rightDescriptionResults.iterator();
//                itDescription.hasNext();) {
//            System.out.println("Right Description = " + itDescription.next().
//                    toString());
//        }
//
//        Set<String> coverageResults = qm.getLOMCoverage(loId, "");
//
//        for (Iterator itCoverage = coverageResults.iterator();
//                itCoverage.hasNext();) {
//            System.out.println("Coverage: " + itCoverage.next().toString());
//        }
//
//        Set<String> installationRResults =
//                qm.getLOMInstallationRemarks(loId, "");
//
//        for (Iterator itInstallationRResults = installationRResults.iterator();
//                itInstallationRResults.hasNext();) {
//            System.out.println("Installation Remarks: " + itInstallationRResults.next().
//                    toString());
//        }
//
//        Set<String> platformRResults =
//                qm.getLOMOtherPlatformRequirements(loId, "");
//
//        for (Iterator itPlatformRResults = platformRResults.iterator();
//                itPlatformRResults.hasNext();) {
//            System.out.println("Other Platform Requirements: " + itPlatformRResults.next().
//                    toString());
//        }

//        Set<String> lifeCycleVersionResults =
//                qm.getLOMLifeCycleVersion(loId, "");
//
//        for (Iterator itLifeCycleVersionResults= lifeCycleVersionResults.iterator();
//                itLifeCycleVersionResults.hasNext();) {
//            System.out.println("Life Cycle Version: " + itLifeCycleVersionResults.next().
//                    toString());
//        }

//         Set<String> educationalDescriptionResults =
//                qm.getLOMEducationalDescription(loId, "");
//
//        for (Iterator itEducationalDescriptionResults= educationalDescriptionResults.iterator();
//                itEducationalDescriptionResults.hasNext();) {
//            System.out.println("Educational Description: " + itEducationalDescriptionResults.next().
//                    toString());
//        }

//        Set<String> typicalAgeRangeResults =
//                qm.getLOMTypicalAgeRange(loId, "");
//
//        for (Iterator itTypicalAgeRangeResults= typicalAgeRangeResults.iterator();
//                itTypicalAgeRangeResults.hasNext();) {
//            System.out.println("Typical Age Range: " + itTypicalAgeRangeResults.next().
//                    toString());
//        }
//        
//        String aggregationLevelResult =
//                qm.getLOMAggregationLevel(loId);
//        System.out.println("Aggregation Level: " + aggregationLevelResult.toString());
//   
//        String copyrightRestrictionsResult =
//                qm.getLOMCopyRightRestrictions(loId);
//        System.out.println("Copyright Restrictions: " + copyrightRestrictionsResult.toString());
//        
//        String costResult =
//                qm.getLOMCost(loId);
//        System.out.println("Cost: " + costResult.toString());
//        
//          String sizeResult =
//                qm.getLOMSize(loId);
//          System.out.println("Size: " + sizeResult.toString());
//        
//        String statusResult =
//                qm.getLOMStatus(loId);
//          System.out.println("Size: " + statusResult.toString());
//          
//          String structureResult =
//                qm.getLOMStructure(loId);
//          System.out.println("Size: " + structureResult.toString());

//         String languageMetadataResult =
//                qm.getLOMMetadataLanguage(loId);
//          System.out.println("Metadata Language: " + languageMetadataResult.toString());
//        
//          String metadataSchemaResult =
//                qm.getLOMMetadataSchema(loId);
//          System.out.println("Metadata Schema: " + metadataSchemaResult.toString());

//         String locationResult =
//                qm.getLOMLocation(loId);
//          System.out.println("Location : " + locationResult.toString());
//         
//         String languageResult =
//                qm.getLOMLanguage(loId);
//          System.out.println("Language : " + languageResult.toString());
//          
//          String formatResult =
//                qm.getLOMTechnicalFormat(loId);
//          System.out.println("Format : " + formatResult.toString());
//          
//           String gCatalogResult =
//                qm.getLOMGeneralCatalogIdentifier(loId);
//          System.out.println("General Catalog : " + catalogResult.toString());

//         String gEntryResult =
//                qm.getLOMGeneralEntryIdentifier(loId);
//          System.out.println("General Entry : " + entryResult.toString());

//        String catalogResult =
//                qm.getLOMMetadataCatalogIdentifier(loId);
//          System.out.println("Metadata Catalog : " + catalogResult.toString());
//        
//         String entryResult =
//                qm.getLOMMetadataEntryIdentifier(loId);
//          System.out.println("Metadata Entry : " + entryResult.toString());

//        String difficultyResult =
//                qm.getLOMEducationalDifficulty(loId);
//          System.out.println("Difficulty : " + difficultyResult.toString());
//        
//          String interactivityLResult =
//                qm.getLOMEducationalInteractivityLevel(loId);
//          System.out.println("Interactivity Level : " + interactivityLResult.toString());

//         String interactivityTResult =
//                qm.getLOMEducationalInteractivityType(loId);
//          System.out.println("Interactivity Type : " + interactivityTResult.toString());

//         String semanticDensityResult =
//                qm.getLOMEducationalSemanticDensity(loId);
//          System.out.println("Semantic Density : " + semanticDensityResult.toString());

//        String humanLanguageResult =
//                qm.getLOMEducationalHumanLanguage(loId);
//        System.out.println("Human Language: " + humanLanguageResult.toString());

//        String humanLanguageResult =
//                qm.getLOMEducationalHumanLanguage(loId);
//        System.out.println("Human Language: " + humanLanguageResult.toString());



        Set<String> relationInstances =
                qm.getLOMSpecificInstances(loId, "hasRelation");
        for (Iterator itRelationInstances =
                relationInstances.iterator();
                itRelationInstances.hasNext();) {
            String relationId =
                    itRelationInstances.next().toString();
            System.out.println("Relation instance : " + relationId);

            //7.1 kind
            String relationKind =
                    qm.getLOMRelationKind(loId, relationId);
            System.out.println("     Kind : " + relationKind);

            ////////7.2.1.1 Resource Identifier Catalog
            String relationResourceIdentifierCatalog =
                    qm.getLOMRelationResourceIdentifierCatalog(loId, relationId);
            System.out.println("     ResourceIdentifierCatalog : " +
                    relationResourceIdentifierCatalog);

            ////////7.2.1.2 Resource Identifier entry
            String relationResourceIdentifierEntry =
                    qm.getLOMRelationResourceIdentifierEntry(loId, relationId);
            System.out.println("      ResourceIdentifierentry : " +
                    relationResourceIdentifierEntry);

            //////7.2.2 Resource Description
            Set<String> relationResourceDescriptionR =
                    qm.getLOMRelationResourceDescription(loId, "", relationId);
            System.out.println("      ResourceDescription : " +
                    relationResourceDescriptionR.toString());
        }


        // EDUCATIONAL SPECIFIC INSTANCES
        Set<String> educationalInstances =
                qm.getLOMSpecificInstances(loId, "hasEducationalInformation");
        for (Iterator itEducationalInstances =
                educationalInstances.iterator();
                itEducationalInstances.hasNext();) {
            String idEducational =
                    itEducationalInstances.next().toString();
            System.out.println("Educational instance : " + idEducational);

            String interactivityTResult =
                    qm.getLOMEducationalInteractivityType(loId, idEducational);
            System.out.println("      Interactivity Type : " +
                    interactivityTResult.toString());

            String learningResourceType =
                    qm.getLOMEducationalLearningResourceType(loId, idEducational);
            System.out.println("      Learning Resource Type : " +
                    learningResourceType.toString());

            String interactivityLevel =
                    qm.getLOMEducationalInteractivityLevel(loId, idEducational);
            System.out.println("      interactivity Level : " +
                    interactivityLevel.toString());

            String semanticDensity =
                    qm.getLOMEducationalSemanticDensity(loId, idEducational);
            System.out.println("      semantic density : " +
                    semanticDensity.toString());

            String intendedUserRole =
                    qm.getLOMEducationalIntendedUserRole(loId, idEducational);
            System.out.println("      intended user role : " +
                    intendedUserRole.toString());

            String context =
                    qm.getLOMEducationalContext(loId, idEducational);
            System.out.println("      context : " + context);

            Set<String> typicalAgeRange =
                    qm.getLOMTypicalAgeRange(loId, "", idEducational);
            System.out.println("      typical age range : " +
                    typicalAgeRange.toString());

            String difficulty =
                    qm.getLOMEducationalDifficulty(loId, idEducational);
            System.out.println("      difficulty : " + difficulty);

            String typicalLearningTime =
                    qm.getLOMEducationalTypicalLearningTimeValue(loId,
                    idEducational);
            System.out.println("      typical learning time value : " +
                    typicalLearningTime.toString());

            Set<String> typicalLearningTimeDes =
                    qm.getLOMEducationalTypicalLearningTimeDescription(loId,
                    context, idEducational);
            System.out.println("      typical learning time description : " +
                    typicalLearningTimeDes.toString());

            String humanLanguage =
                    qm.getLOMEducationalHumanLanguage(loId, idEducational);
            System.out.println("      human language : " +
                    humanLanguage.toString());

        }


        //ANNOTAION SPECIFIC INSTANCES
        Set<String> annotationInstances =
                qm.getLOMSpecificInstances(loId, "hasAnnotation");
        for (Iterator itAnnotationInstances =
                annotationInstances.iterator();
                itAnnotationInstances.hasNext();) {
            String annotationId =
                    itAnnotationInstances.next().toString();
            System.out.println("Annotation instance : " + annotationId);


            Set<String> annotationDateValue =
                    qm.getLOMAnnotationDateValue(loId, annotationId);
            System.out.println("   Date Value: " +
                    annotationDateValue.toString());

            Set<String> annotationDateDescription =
                    qm.getLOMAnnotationDateDescription(loId, "", annotationId);
            System.out.println("   Date description: " +
                    annotationDateDescription.toString());

            Set<String> annotationDescription =
                    qm.getLOMAnnotationDescription(loId, "", annotationId);
            System.out.println("   description: " +
                    annotationDescription.toString());

            String annotationEntityEmail =
                    qm.getLOMAnnotationEntityEmail(loId, annotationId);
            System.out.println("   Entity email: " +
                    annotationEntityEmail.toString());

            String annotationEntityName =
                    qm.getLOMAnnotationEntityName(loId, annotationId);
            System.out.println("   Entity name: " +
                    annotationEntityName.toString());

            String annotationEntityOrganization =
                    qm.getLOMAnnotationEntityOrganization(loId, annotationId);
            System.out.println("   Entity Organization: " +
                    annotationEntityOrganization.toString());

            String annotationEntityFname =
                    qm.getLOMAnnotationEntityFname(loId, annotationId);
            System.out.println("   Entity Fname: " +
                    annotationEntityFname.toString());

        }

        //CLASSIFICATION SPECIFIC INSTANCES
        Set<String> classificationInstances =
                qm.getLOMSpecificInstances(loId, "hasClassification");
        for (Iterator itClassificationInstances =
                classificationInstances.iterator();
                itClassificationInstances.hasNext();) {
            String classificationId =
                    itClassificationInstances.next().toString();
            System.out.println("Classification instance : " + classificationId);

            String classificationPurpose =
                    qm.getLOMClassificationPurpose(loId, classificationId);
            System.out.println("   Purpose: " + classificationPurpose.toString());


            Set<String> classificationTaxonPathSource =
                    qm.getLOMClassificationTaxonPathsource(loId, "",
                    classificationId);
            for (Iterator itclassificationTaxonPathSource =
                    classificationTaxonPathSource.iterator();
                    itclassificationTaxonPathSource.hasNext();) {
                System.out.println("   taxon path source: " +
                        itclassificationTaxonPathSource.next().
                        toString());
            }
            Set<String> classificationtaxonId =
                    qm.getLOMClassificationTaxonPathTaxonId(loId,
                    classificationId);
            System.out.println("   taxon path taxon id: " +
                    classificationtaxonId.toString());


            Set<String> classificationTaxonPathTaxonEntry =
                    qm.getLOMClassificationTaxonPathTaxonEntry(loId, "",
                    classificationId);
            for (Iterator itclassificationTaxonPathTaxonEntry =
                    classificationTaxonPathTaxonEntry.iterator();
                    itclassificationTaxonPathTaxonEntry.hasNext();) {
                System.out.println("   taxon path taxon entry: " +
                        itclassificationTaxonPathTaxonEntry.next().
                        toString());
            }

            Set<String> classificationDescription =
                    qm.getLOMClassificationDescription(loId, "");
            for (Iterator itclassificationDescription =
                    classificationDescription.iterator();
                    itclassificationDescription.hasNext();) {
                System.out.println("   description: " +
                        itclassificationDescription.next().
                        toString());
            }

            Set<String> classificationKeyword =
                    qm.getLOMClassificationKeyword(loId, "");
            for (Iterator itclassificationKeyword =
                    classificationKeyword.iterator();
                    itclassificationKeyword.hasNext();) {
                System.out.println("   keyword: " +
                        itclassificationKeyword.next().
                        toString());
            }
        }

    }
}

    